﻿using System;
using OneMG.Phoenix.Entity;
using OneMG.Phoenix.Respository;
using IBatisNet.DataMapper;
using OneMG.Phoenix.Kernel.IBatisUtil;
using System.Collections.Generic;
using System.Collections;

namespace OneMG.Phoenix.IBatisRepository
{
    public class OrganizationRepository : BaseIBatisDao, IOrganization
    {
        public OrganizationRepository()
            : base("yihaoke_newMap.Config")
        {

        }
        public void AddOrganization(EOrganization entity)
        {
            string stmtId = "OrganizationMap.InsertOrganization";
            base.SqlMapper.Insert(stmtId, entity);
        }

        public EOrganization GetByOrgID(System.Int32 orgID)
        {
            string stmtId = "OrganizationMap.SelectByOrgID";
            return base.SqlMapper.QueryForObject<EOrganization>(stmtId, orgID);
        }

        public void DeleteByOrgID(System.Int32 orgID)
        {
            string stmtId = "OrganizationMap.DeleteByOrgID";
            base.SqlMapper.Update(stmtId, orgID);
        }

        public void UpdateByOrgID(EOrganization entity)
        {
            string stmtId = "OrganizationMap.UpdateByOrgID";
            base.SqlMapper.Update(stmtId, entity);
        }


        public IList<EOrganization> GetByParentID(int parentID)
        {
            string stmtId = "OrganizationMap.SelectByParentID";

           return  base.SqlMapper.QueryForList<EOrganization>(stmtId, parentID);


        }


        public IList<EOrganization> GetByParentIDPagedList(int parentID , int pageSize, int pageIndex, out int totalRecord)
        {


            totalRecord = base.SqlMapper.QueryForObject<int>("SelectByParentIDRecord", parentID);

            if (pageIndex > totalRecord)
                pageIndex = 1;

            int startPage = pageSize * pageIndex - pageSize;

            int endPage = pageSize * pageIndex;

            Hashtable ht = new Hashtable();
            ht.Add("ParentID", parentID);
            ht.Add("StartPage", startPage);
            ht.Add("EndPage", endPage);

            string stmtId = "OrganizationMap.DeleteByOrgID";

            return base.SqlMapper.QueryForList<EOrganization>(stmtId, ht);
           


        }



    }
}

